import request from '@/utils/request';
import Fetch from '@/utils/fetch';
/**
 * 整个项目模块公共
 */
const base = {

  /**
   *  获取流程进度
   */
  getProgress: (code) => {
    return request({
      url: `busItemProcess/getItemList`,
      method: 'post',
      data: {
        itemCode: code,
      },
    });
  },

  /**
   * 获取总体数据包
   */
  getAllProjectData: (itemCode) => {
    return request({
      url: 'busItemInfo/getWorkDetail',
      method: 'post',
      data: {
        itemCode,
      },
    });
  },
  /**
 * 终止项目
 */
  endProject(params) {
    return request({
      url: 'busItemProcess/termination',
      method: 'post',
      data: params,
    });
  },
  /**
 * 撤销项目
 */
  backItem(itemCode) {
    return request({
      url: 'busItemInfo/revoke',
      method: 'post',
      data: {
        itemCode,
      },
    });
  },
  /**
   *
   * 需求撤销
   */
  backDemand(itemCode) {
    return request({
      url: 'busItemInfo/demand/revoke',
      method: 'post',
      data: {
        itemCode,
      },
    });
  },

};
// 需求
const demand = {

  /**
 * 创建和保存需求
 */
  createOrSaveNeedInfo(params, prefixed) {
    return request({
      url: `/busItemDemand/${prefixed}`,
      method: 'post',
      data: { ...params, },
    });
  },

  /**
 * 获取需求列表
 * 1
 */
  getNeedList: ({
    pageNum,
    pageSize,
    query = '',
    code = '',
    level = '',
    showState = '',
    itemSource = '',
    principal = '',
    users = '',
  } = {}) => Fetch.post('busItemDemand/getPage', {
    pageNum,
    pageSize,
    query,
    temp: code,
    level,
    showState,
    itemSource,
    principal,
    users,
  }),

  /**
   * 删除需求
   * @param {*} code
   */
  del(id) {
    return request({
      url: `/busItemDemand/delete`,
      method: 'post',
      data: { id, },
    });
  },
  /**
 * 获取进度
 */
  getProgress(code) {
    return request({
      url: `busItemProcess/getItemList`,
      method: 'post',
      data: {
        itemCode: code,
      },
    });
  },

  /**
 *  获取需求 编辑页面数据
 */

  getNeedInfo(code) {
    return request({
      url: `/busItemDemand/getDetail`,
      method: 'post',
      data: {
        itemCode: code,
      },
    });
  },

  /**
 * 需求分配 1
 */

  setAssign(params) {
    return request({
      url: `busItemProcess/distribution`,
      method: 'post',
      data: {
        ...params,
      },
    });
  },

  /**
 * 获取流程面板 红点数量
 */

  getProcessNumm: () => {
    return request({
      url: `/busItemDemand/getPcRedInfo`,
      method: 'post',
      data: {},
    });
  },
  /**
 * 获取调研信息
 */

  getReachInfo(code) {
    return request({
      url: `busItemInvestigate/getDetail`,
      method: 'post',
      data: {
        itemCode: code,
      },
    });
  },
  /**
 * 提交 保存 调研信息
 */
  confirmOrSaveRearchInfo(apiname, params) {
    return request({
      url: `busItemInvestigate/${apiname}`,
      method: 'post',
      data: { ...params, },
    });
  },

  /**
 *  评审 不同状态的提交 1
 */
  submitReview(params, apiName = 'pass',) {
    return request({
      url: `busItemProcess/demandReview/${apiName}`,
      method: 'post',
      data: { ...params, },
    });
  },

  /**
 * 发起投票1
 */
  submitVote(params) {
    return request({
      url: `busVote/initiate/demand`,
      method: 'post',
      data: { ...params, },
    });
  },

  /**
 * 获取下次投票轮次信息
 */
  getNextVoteInfo(code) {
    return request({
      url: `busVote/index/demand`,
      method: 'post',
      data: { linked: code, },
    });
  },
  /**
 * 获取评审审核页面数据
 */

  getReViewInfo(code) {
    return request({
      url: `busItemDemand/getReviewDetail`,
      method: 'post',
      data: {
        itemCode: code,
      },
    });
  },

  /**
 * 追加投票
 */
  addedVote(id, users) {
    return request({
      url: `busVote/replenish`,
      method: 'post',
      data: {
        id,
        users,
      },
    });
  },
  /**
 * 撤销投票
 */
  backVote(id) {
    return request({
      url: `busVote/revoke`,
      method: 'post',
      data: {
        id,
      },
    });
  },
  /** *
 * 获取投票数据
 */
  getVoteData(code, id) {
    const params = {
      itemCode: code,
    };
    if (id) {
      Object.assign(params, { processId: id, });
    }
    return request({
      url: `busVote/info/demand`,
      method: 'post',
      data: params,
    });
  },

};
// 立项
const setUp = {

  /**
 * 创建和保存项目立项
 *
 */
  createOrSaveSetup(params, prefixed) {
    return request({
      url: `busItemInfo/${prefixed}`,
      method: 'post',
      data: { ...params, },
    });
  },
  /**
   * 删除未提交
   */
  del(id) {
    return request({
      url: 'busItemInfo/delete',
      method: 'post',
      data: {
        id,
      },
    });
  },
  /**
 *  获取流程红点数据
 *
 */
  getProcessData() {
    return request({
      url: `busItemInfo/getRedInfo`,
      method: 'post',
      data: {},
    });
  },

  /**
 * 获取列表数据
 *
 */
  // getListData(params) {
  //   return request({
  //     url: 'busItemInfo/getPage',
  //     method: 'post',
  //     data: {
  //       temp: params.W.code,
  //       query: params.keyWord,
  //       ...params.W.filterValues,
  //       pageNum: params.P,
  //       pageSize: params.N,
  //       id: params.W.id,
  //     },
  //   });
  // },
  getListData: ({
    pageNum,
    pageSize,
    code = '',
    query = '',
    level = '',
    principal = '',
    sponsor = '',
    showState = '',
    users = '',
    id = '',
  } = {}) => Fetch.post('busItemInfo/getPage', {
    pageNum,
    pageSize,
    temp: code,
    query,
    level,
    principal,
    sponsor,
    showState,
    users,
    id,
  }),

  /**
 * 创建任务
 */
  createdTask(params) {
    return request({
      url: 'busItemWork/save',
      method: 'post',
      data: {
        ...params,
      },
    });
  },
  /**
 * 获取任务列表
 */
  getTaskList(params) {
    return request({
      url: 'busItemInfo/getWorkList',
      method: 'post',
      data: {
        ...params,
      },
    });
  },
  /**
 * 保存模板
 */
  saveTemplate(params) {
    return request({
      url: 'busItemWork/saveTemp',
      method: 'post',
      data: {
        ...params,
      },
    });
  },

  /**
 * 获取模板列表
 */
  getTemplateList() {
    return request({
      url: 'busItemTemp/getList',
      method: 'post',
      data: {},
    });
  },

  /**
 * 引用模板
 */

  qutoTemplate(code, id) {
    return request({
      url: 'busItemWork/quote',
      method: 'post',
      data: {
        itemCode: code,
        tempId: id,
      },
    });
  },

  /**
 * 删除任务
 */
  deletedTask(id) {
    return request({
      url: 'busItemWork/delete',
      method: 'post',
      data: {
        id,
      },
    });
  },

  /**
 * 编辑任务
 */
  editedTask(params) {
    return request({
      url: 'busItemWork/update',
      method: 'post',
      data: {
        ...params,
      },
    });
  },

  /**
 * 编辑子任务
 */
  editedTaskChlid(params) {
    return request({
      url: 'busItemWork/updateChild',
      method: 'post',
      data: {
        ...params,
      },
    });
  },

  /**
 * 创建子任务
 */
  createdTaskChild(params) {
    return request({
      url: 'busItemWork/saveChild',
      method: 'post',
      data: {
        ...params,
      },
    });
  },

  /**
 * 获取编辑数据
 */
  getEditData(code) {
    return request({
      url: 'busItemInfo/getDetail',
      method: 'post',
      data: {
        itemCode: code,
      },
    });
  },

  /**
 * 评审通过
 */
  reviewPass(params) {
    return request({
      url: `busItemProcess/infoReview/${params.result}`,
      method: 'post',
      data: params,
    });
  },

  /**
 * 结果确认  不通过 和 通过
 * @param {} itemCode
 */
  confirmResult(params, apiName = 'pass') {
    return request({
      url: `busItemProcess/itemReview/${apiName}`,
      method: 'post',
      data: params,
    });
  },
  /**
 * 获取方案制定编辑页面数据
 * 1
 */

  reviewInfo(itemCode) {
    return request({
      url: 'busItemInfo/getWorkDetail',
      method: 'post',
      data: {
        itemCode,
      },
    });
  },
};
// 实施
const impose = {
  /**
   * 获取 项目实施列表
   *
   */
  getImposeListGantt(params) {
    return request({
      url: `busItemInfo/getImplPage`,
      method: 'post',
      data: {
        temp: params.W.code,
        query: params.keyWord,
        pageNum: params.P,
        pageSize: params.N,
      },
    });
  },

  getImposeListMain: ({
    pageNum,
    pageSize,
    query = '',
    code = '',
  } = {}) => Fetch.post('busItemInfo/getImplPage', {
    pageNum,
    pageSize,
    query,
    temp: code,

  }),

  /**
   *  处理 项目实施
   *
   */
  handleImpose(params) {
    return request({
      url: `busItemWork/make`,
      method: 'post',
      data: params,
    });
  },

  /**
   *  获取任务评审历史
   */
  taskInjectHistory(id) {
    return request({
      url: `busItemWork/getMakeList`,
      method: 'post',
      data: {
        workId: id,
      },
    });
  },

  /**
   * 任务处理
   */
  handleTask(params) {
    return request({
      url: `busItemWork/make`,
      method: 'post',
      data: params,
    });
  },
  /**
 *
 * 任务处理补充
 */
  handletaskAppend(params) {
    return request({
      url: `busItemWork/additional`,
      method: 'post',
      data: params,
    });
  },

  /**
   * 确认结果
   *
   */
  confirmResult(itemCode) {
    return request({
      url: `busItemProcess/implReview/confirm`,
      method: 'post',
      data: {
        itemCode,
      },
    });
  },

  /**
   * 获取  申请列表
   */

  changeList(itemCode) {
    return request({
      url: `busItemWorkReview/change/list`,
      method: 'post',
      data: { itemCode, },
    });
  },

  /**
   * 变更申请
   * @param {} params
   */
  changeApply(params, field) {
    let data = {};
    if (field === 'apply') {
      data = params;
    }
    if (field !== 'apply') {
      data = {
        changeId: params,
      };
    }
    return request({
      url: `busItemWorkReview/change/${field}`,
      method: 'post',
      data: data,
    });
  },

};
const template = {
  /**
 * 创建模板
 *
 */
  // createTemplate(params) {
  //   return request({
  //     url: `/busItemTemp/save`,
  //     method: 'post',
  //     data: { ...params, },
  //   });
  // },
  /**
 * 编辑某个模板
 */
  // editTemplate(params) {
  //   return request({
  //     url: `/busItemTemp/update`,
  //     method: 'post',
  //     data: { ...params, },
  //   });
  // },

  /**
  * 模板 创建-编辑 操作
  * @param {*} params
  * @param {*} isEdit  默认 创建
  */
  createOrEditTemplate(params, isEdit = false) {
    return request({
      url: `/busItemTemp/${isEdit ? 'update' : 'save'}`,
      method: 'post',
      data: { ...params, },
    });
  },

  /**
 * 获取模板列表
 */
  templateList(params = {}) {
    return request({
      url: `/busItemTemp/getList`,
      method: 'post',
      data: params,
    });
  },
  /**
 * 删除某个模板
 */
  deleteTemplate(id) {
    return request({
      url: `/busItemTemp/delete`,
      method: 'post',
      data: {
        id: id,
      },
    });
  },

  /**
 * 获取对应模板的任务列表
 */
  getTaskList(tempId, parentId = 1) {
    return request({
      url: `/busItemTemp/getWorkList`,
      method: 'post',
      data: {
        tempId,
        // parentId,
      },
    });
  },

  /**
 * 创建任务
 */
  createTask(params) {
    return request({
      url: `/busItemTemp/saveWork`,
      method: 'post',
      data: { ...params, },
    });
  },

  /**
 * 删除任务
 */
  deleteTask(id) {
    return request({
      url: `/busItemTemp/deleteWork`,
      method: 'post',
      data: { id: id, },
    });
  },

  /**
 * 编辑某个任务
 */
  editTask(params) {
    return request({
      url: `/busItemTemp/updateWork`,
      method: 'post',
      data: { ...params, },
    });
  },

};
/**
 * 项目查询
 */
const search = {
  search: ({
    pageNum,
    pageSize,
    startTime = '',
    endTime = '',
    level = '',
    showStateStr = '',
    principal = '',
    users = '',
    createUser = '',
    query = '',
  } = {}) => Fetch.post('busItemDemand/getItemDemandAll', {
    pageNum,
    pageSize,
    startTime,
    endTime,
    level,
    showStateStr,
    principal,
    users,
    createUser,
    query,
  }),

};
/**
 *  项目名称列表
 * @returns
 */
const projectNameList = () => Fetch.post('/busItemInfo/getList', {});
const ProjectAPI = {
  base,
  demand,
  setUp,
  impose,
  template,
  search,
  projectNameList,
};

export default ProjectAPI;
